//
//  JSTPersonalViewController.m
//  KYKJPackDemo
//
//  Created by 01 on 17/5/8.
//  Copyright © 2017年 ???. All rights reserved.
//

#import "JSTPersonalViewController.h"
#import "JSTUserPublicModel.h"
#import "JSTPersonalHeaderImageView.h"
#import "JSTLoginViewController.h"
#import "JSTMyDynamicViewController.h"
#import "JSTSetupViewController.h"
#import "JSTFeedBackViewController.h"


@interface JSTPersonalViewController ()<UITableViewDelegate, UITableViewDataSource, JSTAlertViewDelegate>

@property (nonatomic, strong) UITableView *tabView;

@property (nonatomic, strong) NSMutableArray *data;

@property (nonatomic, strong) NSMutableArray *iconData;

@property (nonatomic, strong) JSTUserPublicModel *model;

@property (nonatomic, strong) JSTPersonalHeaderImageView *headerView;

@end

@implementation JSTPersonalViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self createContent];
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    [self.navigationController setNavigationBarHidden:YES animated:animated];
    [self createData];
    [self.headerView createContent:_model];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:animated];
}

- (void)requestUserData
{
    [JSTNewServer requestUserInfo:@"" success:^(NSDictionary *dataDic)
    {
        
    } error:^(NSString *errStr)
    {
        
    }];
}

- (void) createData
{
    _data = [NSMutableArray arrayWithObjects:@"浏览历史", @"我的动态", nil];
    _iconData = [NSMutableArray arrayWithObjects:@"personal_view_normal", @"personal_ state_normal", nil];
    
    _model = [[JSTUserPublicModel alloc] init];
    _model.iconUrl = [[JSTSystemInfo userDict] valueForKey:@"icon"];
    _model.nickName = [[JSTSystemInfo userDict] valueForKey:@"name"];
}

- (void) createContent
{
    [self.view addSubview:self.tabView];
    [self.tabView addSubview:self.headerView];
    [self.headerView createContent:_model];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"PersonalCell"];
    if (indexPath.section == 0)
    {
        if (!cell)
        {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"PersonalCell"];
        }
        cell.textLabel.text = _data[indexPath.row];
        cell.imageView.image = [UIImage imageNamed:[_iconData safeObjectAtIndex:indexPath.row]];
    }else
    {
        if (!cell)
        {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"PersonalCell"];
        }
        cell.textLabel.text = @"设置";
        cell.imageView.image = [UIImage imageNamed:@"personal_set_normal"];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone; // 设置点按无色彩变化
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; //显示最右边的箭头
    
    return cell;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0)
    {
        return _data.count;
    }
    return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 1.;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 10.;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0)
    {
        if (indexPath.row == 0)
        {
//            JSTHistoryViewController *historyViewController = [[JSTHistoryViewController alloc] init];
//            historyViewController.currentStatus = @"ios";
//            [self.navigationController pushViewController:historyViewController animated:YES];
            
//            JSTAlertView *alertView = [[JSTAlertView alloc] initWithTitle:@"" message:@"敬请期待" customView:nil delegate:self cancelButtonTitle:@"取 消" otherButtonTitles:@"确 定"];
//            [alertView setConfirmBlock:^{
//                
//            }];
//            [alertView show];
            
            JSTFeedBackViewController *feedBakViewController = [[JSTFeedBackViewController alloc] init];
            [self.navigationController pushViewController:feedBakViewController animated:YES];
            
        }
        else if (indexPath.row == 1)
        {
            JSTMyDynamicViewController *myDynamicViewController = [[JSTMyDynamicViewController alloc] init];
            [self.navigationController pushViewController:myDynamicViewController animated:YES];
        }
        else if (indexPath.row == 2)
        {
            JSTMyDynamicViewController *myDynamicViewController = [[JSTMyDynamicViewController alloc] init];
            [self.navigationController pushViewController:myDynamicViewController animated:YES];
        }
    }else
    {
        JSTSetupViewController *setupViewController = [[JSTSetupViewController alloc] init];
        [self.navigationController pushViewController:setupViewController animated:YES];
    }
}

//cell 分割线到头
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ([cell respondsToSelector:@selector(setSeparatorInset:)])
    {
        [cell setSeparatorInset:UIEdgeInsetsZero];
    }
    if ([cell respondsToSelector:@selector(setLayoutMargins:)])
    {
        [cell setLayoutMargins:UIEdgeInsetsZero];
    }
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    CGPoint point = scrollView.contentOffset;
    if (point.y < - 200)
    {
        CGRect rect = [_tabView viewWithTag:101].frame;
        rect.origin.y = point.y;
        rect.size.height = -point.y;
        [_tabView viewWithTag:101].frame = rect;
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/**
 查看头像大图
 */
- (void)SeeBigPicture{
    
}

/**
 登录或注销
 */
- (void)LoginOrLogout{
    
}

- (UITableView *)tabView
{
    if (!_tabView) {
        _tabView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
        _tabView.dataSource = self;
        _tabView.delegate = self;
        _tabView.contentInset = UIEdgeInsetsMake(200, 0, 0, 0);
    }
    return _tabView;
}

- (JSTPersonalHeaderImageView *)headerView
{
    if (!_headerView) {
        _headerView = [[JSTPersonalHeaderImageView alloc] initWithFrame:CGRectMake(0, -kCurrentScreenWidth(200), kDeviceWidth, kCurrentScreenWidth(200))];
        self.headerView.tag = 101;
        self.headerView.contentMode = UIViewContentModeScaleAspectFill;
        self.headerView.image = [UIImage imageNamed:@"my_integral_bg"];
    }
    return _headerView;
}

@end
